/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : DeviceSelect.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "DeviceSelectEvent.h"
#include "./win/NetmenuSetupEvent.h"

INT32S WinDeviceSelectMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinDeviceSelectOnShow(hwnd, lpParam) ;
    }
    return 0 ;
}

void SetWinDeviceSelectPalette_720P(void)
{
    YUVENTRY mask_para[4] = {0,0,0,4095};
    AWSetAlphaMask(0,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 16392,0x8000 | 21176,0x8000 | 17752,0x8000 | 16392,17592,19496,19832,19656,19992,18104,17673,17817,15864,15721,15912,16344};
    AWSetPalette(0,16, palette_para);
    return ;
}

void SetWinDeviceSelectPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
	case OsdSize720p:
	    RECT WindowRect720p = {0,0,1280,720};
	    pControl->winrect = WindowRect720p;
	    CREATEWINDOWPARAM WindowPara720p = {1,{{0,0,1280,720},    {0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},    SetWinDeviceSelectPalette_720P};
	    AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&WindowPara720p);
	    break;
    }//end of switch
    return;
}

HWND *CreateControlWinDeviceSelect_720P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
	case OsdSize720p:
	     CREATEWINDOWPARAM window_para720p = {1,{{0,0,1280,720},{0,0,0,0},{0,0,0,0},{0,0,0,0}},{PF_PALETTE_256,0,0,0},SetWinDeviceSelectPalette_720P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinDeviceSelect_720P",WS_OVERLAPPEDWINDOW,
		                      0,0,1280,720,NULL, (INT32S)&window_para720p,WinDeviceSelectMsgProc_720P) ;
            pNewControl->win_id = 0 ;
            break ;
    }//end of switch
            return pNewControl;
}

void SetWinDeviceSelectInfoPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
	case OsdSize720p:
            pControl->winrect.top = pControl->parent->winrect.top + 0;
            pControl->winrect.left = pControl->parent->winrect.left + 0;
            pControl->winrect.width = 1280;
            pControl->winrect.height = 720;
            pControl->draw_info_num = 8;
            RECT DrawRect720p[8] = {
            {pControl->winrect.left + 284,pControl->winrect.top + 350,150,180},
            {pControl->winrect.left + 484,pControl->winrect.top + 350,150,180},
            {pControl->winrect.left + 684,pControl->winrect.top + 350,150,180},
            {pControl->winrect.left + 884,pControl->winrect.top + 350,150,180},
	     {pControl->winrect.left + 284,pControl->winrect.top + 560,132,36},
	     {pControl->winrect.left + 294,pControl->winrect.top + 484,132,36},
	     {pControl->winrect.left + 164,pControl->winrect.top + 390,60,60},
	     {pControl->winrect.left + 1088,pControl->winrect.top + 390,60,60},			
            };
            for(iLoop=0; iLoop < 8; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &DrawRect720p[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S WinDeviceSelectInfoMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinDeviceSelectInfoOnShow(hwnd, lpParam) ;
        case WM_KEYDOWN:
            return WinDeviceSelectInfoOnKeyPress(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlWinDeviceSelectInfo_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- WinDeviceSelectInfo
    HWND *pNewControl;
    switch(CurOsdSize){
	case OsdSize720p:
            pNewControl = AWCreateWinControl("TControl","WinDeviceSelectInfo_720P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      0,0,1280,720,pParent,0,WinDeviceSelectInfoMsgProc_720P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 8;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO DrawDatas720p[8] = {
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},//ICON_DEVICENAME_BCK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RESOURCE_STRING_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)0,DT_RLE_BMP_DATA},
                          };
            memcpy(pNewControl->draw_info,DrawDatas720p, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinDeviceSelect_720P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinDeviceSelect = CreateControlWinDeviceSelect_720P(NULL,CurrentOsdSize);
    SetWinDeviceSelectPos_720P(pWinDeviceSelect,CurrentOsdSize);

    pNewControl= CreateControlWinDeviceSelectInfo_720P(pWinDeviceSelect,CurrentOsdSize);
    SetWinDeviceSelectInfoPos_720P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinDeviceSelect;
    pWin->pFocusControl = AWFindWinCtrlByName("WinDeviceSelectInfo_720P");
    return pWinDeviceSelect;
}

void WinResetWinDeviceSelectControlsPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinDeviceSelect
            SetWinDeviceSelectPos_720P(pControl,CurOsdSize) ;
            break ;
        case 1://WinDeviceSelectInfo
            SetWinDeviceSelectInfoPos_720P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinDeviceSelectPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinDeviceSelect_720P");
    if(pControl == NULL) return ;

    WinResetWinDeviceSelectControlsPos_720P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinDeviceSelectPos_720P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

